package org.meeting.radish.util;

import org.meeting.radish.entity.User;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;

public class EncodeUtil {

    public static void userPasswordEncode(User user) throws NoSuchAlgorithmException {
        if (user == null || user.getPassword() == null) {
            return;
        }

        MessageDigest instance = MessageDigest.getInstance("sha-1");
        instance.update(user.getPassword().getBytes(StandardCharsets.UTF_8));
        String pass = Base64.getEncoder().encodeToString(instance.digest());
        user.setPassword(pass);
    }

}
